define(['jquery',
        'underscore',
        'handlebar',
        'backbone',
        'GlobalConfiguration',
        '../../collection/sellerInfo/CsellerInfo',    
        'text!../../../templates/common/home-brand-tiles.html',
        'text!../../../templates/common/home-retailer-tiles.html'
],
function ($,
         _,
         Handlebar,
         Backbone,
         GConfigs,
         CollectionSellerInfo,
         sellerInfoTemplate,
         homeBrandTiles
         ) {

    window.VItemsRow = Backbone.View.extend({
        el: $('section#items-row'),
        initialize: function () {

            //console.log('views/product/VProducts')
        },
        events: {
            'click a.product-detailer-view': 'loadProductDetailsView',
        },        
        render: function (responce) {
            var SellerInfoTemplate = Handlebars.compile(sellerInfoTemplate);
            var sellerInfoTemplateDOM = SellerInfoTemplate(responce.toJSON());
            this.$el.html(sellerInfoTemplateDOM);

            this.loadHomeRetailerTiles();
        },        
        loadSellerInfo: function () {           
            var that = this;
            var collectionSellerInfo = new CollectionSellerInfo();
            collectionSellerInfo.fetch({
                success: function (responce) {                   
                    that.render(responce);
                },
                error: function (err) {
                    console.log("%c ERROR: in fetching Seller Information", "color: red; font-size:small", err);
                }
            });
        },       
        removeSerachProductView: function (prodId) {
            $(this.el).empty();            
        },

        loadHomeRetailerTiles: function () {
            var _self = this;
            var reqObj = {};
            var URL = GConfigs.CONSTANTS.PROTOCOL + "://" +
                      GConfigs.CONSTANTS.HOST_NAME + ":" +
                      GConfigs.CONSTANTS.PORT_NO +
                      GConfigs.CONSTANTS.REST_PATH +
                      GConfigs.API.fetchHomeRetailerTilesInfo;
            $.ajax({
                url: URL,
                dataType: 'json',           
                success: function (responce) {                  
                    var homeBrandTilesTemplate = Handlebars.compile(homeBrandTiles);
                    var homeBrandTilesTemplateDOM = homeBrandTilesTemplate(responce.rows);
                    _self.$el.append(homeBrandTilesTemplateDOM);
                },
                error: function () {
                    console.log("%c ERROR: in fetching Retailer Information", "color: red; font-size:small", err);
                }
            })
        }
    });
    return VItemsRow;
});